<?php
/* *
 * 功能：用户列表
 * 日期：2016-02-17
 * 源码来自：资源e站（Zye.cc）
 */
?>
<?php
$mod='blank';
include("../includes/common.php");
$title='代理配置';
$plus = true;
include './head.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
  <nav class="navbar navbar-fixed-top navbar-default">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
          <span class="sr-only">导航按钮</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="./">后台管理</a>
      </div><!-- /.navbar-header -->
      <div id="navbar" class="collapse navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
          <li>
            <a href="./"><span class="glyphicon glyphicon-user"></span> 平台首页</a>
          </li>
		  <li>
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-cloud"></span> 用户管理<b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="./dl.php">用户列表</a></li>
			  <li><a href="./search.php">搜索用户</a><li>
            </ul>
          </li>
		  <li><a href="./log.php"><span class="glyphicon glyphicon-calendar"></span> 日志查看</a></li>
		  <li><a href="../"><span class="glyphicon glyphicon-home"></span> 返回首页</a></li>
          <?php require_once('nav.php'); ?><li><a href="./login.php?logout"><span class="glyphicon glyphicon-log-out"></span> 退出登录</a></li>
        </ul>
      </div><!-- /.navbar-collapse -->
    </div><!-- /.container -->
  </nav><!-- /.navbar -->
  <div class="container" style="padding-top:70px;">
    <div class="col-sm-12 col-md-10 center-block" style="float: none;">
<?php
if($_GET['do'] == "del"){
	$id = intval($_GET['id']);
	$sql="delete from `tell_level` where `id`='{$id}' limit 1";
    if($DB->query($sql)){echo "<script language='javascript'>alert('删除成功！');history.go(-1);</script>";}
    else{echo "<script language='javascript'>alert('删除失败！');history.go(-1);</script>";}	
}elseif($_GET['do'] =="edit"){ 
	$shopid=empty($_GET['id'])?exit('该级别不存在!'):daddslashes($_GET['id']);
	  $shop = $DB->get_row("select * from tell_level where id='{$shopid}' limit 1");
	  if($_POST['type']=='edit'){
      $name=empty($_POST['name'])?exit("名称不能为空!"):daddslashes($_POST['name']);
      $price=empty($_POST['price'])?exit("金额不能为0元!"):daddslashes($_POST['price']);
	  $buyprice=empty($_POST['buyprice'])?exit("购买金额不能为0元!"):daddslashes($_POST['buyprice']);
      if($price*100<1){exit('金额不能小于0.01元！');}
      $sql="update `tell_level` set `name`='{$name}',`price`='{$price}',`buyprice`='{$buyprice}' where `id`='{$shopid}'";
      if($DB->query($sql)){echo "<script language='javascript'>alert('修改成功！');history.go(-1);</script>";}
      else{echo "<script language='javascript'>alert('修改失败！');history.go(-1);</script>";} 
	  }else{
?>
		<div class="panel panel-primary">
        <div class="panel-heading"><h3 class="panel-title">代理级别配置</h3></div>
        <div class="panel-body">
        <form action="?do=edit&id=<?=$_GET['id']?>" class="form-horizontal" method="post">
								<input type="hidden" name="type" value="edit">
                                <div class="input-group">
                                  <span class="input-group-addon">代理名称</span>
                                  <input type="text" name="name" value="<?=$shop['name']?>" class="form-control">
                                  
                                </div><br/>
                                <div class="input-group">
                                  <span class="input-group-addon">拨打价格</span>
                                  <input type="text" name="price" value="<?=$shop['price']?>" class="form-control">
                                </div><br/>
                                <div class="input-group">
                                  <span class="input-group-addon">购买价格</span>
                                  <input type="text" name="buyprice" value="<?=$shop['buyprice']?>" class="form-control">
                                </div><br/>

                                  <div class="form-group">
                                    <div class="col-sm-12"><input type="submit" name="submit" value="修改" class="btn btn-primary form-control"/></div>
                                  </div>
                              </form>
        </div>
        </div>
<?php }}elseif($_GET['do'] == "add"){ 
	if($_POST['type']=='add'){
      $name=empty($_POST['name'])?exit("名称不能为空!"):daddslashes($_POST['name']);
      $price=empty($_POST['price'])?exit("金额不能为0元!"):daddslashes($_POST['price']);
	  $buyprice=empty($_POST['buyprice'])?exit("购买金额不能为0元!"):daddslashes($_POST['buyprice']);
      if($price*100<1){exit('金额不能小于0.01元！');}
      $sql="insert into `tell_level` (`name`,`price`,`buyprice`,`addtime`) values ('{$name}','{$price}','{$buyprice}','".date("Y-m-d H:i:s")."')";
      if($DB->query($sql)){echo "<script language='javascript'>alert('添加成功！');history.go(-1);</script>";}
      else{echo "<script language='javascript'>alert('添加失败！');history.go(-1);</script>";} 
	}else{

?>
<div class="panel panel-primary">
        <div class="panel-heading"><h3 class="panel-title">代理级别</h3></div>
        <div class="panel-body">
        <form action="?do=add" class="form-horizontal" method="post">
								<input type="hidden" name="type" value="add">
                                <div class="input-group">
                                  <span class="input-group-addon">级别名称</span>
                                  <input type="text" name="name" value="" class="form-control">
                                  
                                </div><br/>
                                <div class="input-group">
                                  <span class="input-group-addon">拨打价格</span>
                                  <input type="text" name="price" value="" class="form-control">
                                </div><br/>
                                
                                <div class="input-group">
                                  <span class="input-group-addon">购买价格</span>
                                  <input type="text" name="buyprice" value="<?=$shop['buyprice']?>" class="form-control">
                                </div><br/>

                                  <div class="form-group">
                                    <div class="col-sm-12"><input type="submit" name="submit" value="添加" class="btn btn-primary form-control"/></div>
                                  </div>
                              </form>
        </div>
        </div>
<?php

	}}else{

$pagesize=30;
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
{
 $pages++;
 }
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
$page=1;
}
$offset=$pagesize*($page - 1);
$sql = ' 1';
$rs=$DB->query("SELECT * FROM tell_level WHERE{$sql} order by id desc limit $offset,$pagesize");
?>
      <div class="panel panel-primary">
        <div class="panel-heading"><h3 class="panel-title">代理级别</h3><p></p><h3 class="panel-title"><a href="?do=add">添加级别</a></h3></div>
        <div class="table-responsive">
        <table class="table table-striped">
        <table class="table table-striped">
          <thead><tr><th>#</th><th>名称</th><th>拨打价格</th><th>购买价格</th><th>添加时间</th><th>操作</th></tr></thead>
          <tbody>
		  
<?php
while($res = $DB->fetch($rs))
{
?>
<tr>
<td><?=$res['id']?></td>
<td><?=$res['name']?></td>
<td><?=$res['price']?></td>
<td><?=$res['buyprice']?></td>
<td><?=$res['addtime']?></td>
<td><a href="?do=del&id=<?=$res['id']?>" class="label label-danger">删除</a><a href="?do=edit&id=<?=$res['id']?>" class="label label-warning">修改</a></td>
</tr>
<?php
}
?>
          </tbody>
        </table>
      </div>
<?php
echo'<ul class="pagination">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li><a href="dl.php?page='.$first.$link.'">首页</a></li>';
echo '<li><a href="dl.php?page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}
for ($i=1;$i<$page;$i++)
echo '<li><a href="dl.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="disabled"><a>'.$page.'</a></li>';
for ($i=$page+1;$i<=$pages;$i++)
echo '<li><a href="dl.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '';
if ($page<$pages)
{
echo '<li><a href="dl.php?page='.$next.$link.'">&raquo;</a></li>';
echo '<li><a href="dl.php?page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}
echo'</ul>';
#分页
	}
?>
</div>
    </div>
  </div>